import java.util.*;

public class Lab14Task02 {

	public static void main(String[] args) {
		int row, column, value;
		int[][] a = new int[4][3];

		Scanner kb = new Scanner(System.in);

		System.out.println("Enter the integar elements of a 3 * 4 2D-array:");

		for (row = 0; row < 4; row++) {
			for (column = 0; column < 3; column++) {
				a[row][column] = kb.nextInt();
			}
		}

		System.out.print("Enter the integar value to search for:");
		value = kb.nextInt();

		int[] RowCol = linearSearch2D(a, value);

		if (RowCol[0] == -1 && RowCol[1] == -1)
			System.out.printf("The value %d does not exist in the array.", value);
		else
			System.out.printf("The value %d exists in the array at (row %d , column %d)", value, RowCol[0], RowCol[1]);

		kb.close();

	}

	private static int[] linearSearch2D(int[][] array, int value) {

		int row, column;
		int[] RowCol = { -1, -1 };

		for (row = 0; row < 3; row++) {
			for (column = 0; column < 4; column++) {
				if (array[column][row] == value) {
					RowCol[0] = column;
					RowCol[1] = row;
					return RowCol;
				}
			}
		}
		return RowCol;
	}

}
